package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.exception.Ex;
import com.general.framework.core.lang.Lists;

import java.util.List;
import java.util.Objects;

/**
 * 业务员订单操作定义
 */
public enum ClerkOrderActionEnum implements IEnum<String> {

    ACCEPT("ACCEPT", "业务员接单", "确认接单",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.WAIT_ACCEPT), OrderStatusEnum.WAIT_CONFIRM, Boolean.FALSE),

    CLERK_BACKOUT("CLERK_BACKOUT", "业务员申请撤单", "申请撤单",ClerkActionTypeEnum.BTN.value(), Lists.asList(OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_VISIT,OrderStatusEnum.WAIT_BARGAIN,OrderStatusEnum.WAIT_PAY), OrderStatusEnum.BACKOUT_AUDITING, Boolean.TRUE),

    CONFIRM("CONFIRM", "业务员确认订单", "确认订单",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.WAIT_CONFIRM), OrderStatusEnum.WAIT_VISIT, Boolean.FALSE),

    CLERK_EDIT("CLERK_EDIT", "修改上门时间", "修改上门时间",ClerkActionTypeEnum.ACTION.value(), Lists.asList(OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_VISIT), null, Boolean.FALSE),

    VISIT("VISIT", "业务员上门", "我已上门",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.WAIT_VISIT), OrderStatusEnum.WAIT_QUALITY, Boolean.FALSE),

    SUBMIT_QUALITY("SUBMIT_QUALITY", "业务员提交质检", "开始质检",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.WAIT_QUALITY), OrderStatusEnum.WAIT_PAY, Boolean.FALSE),

    COMPLETE("COMPLETE", "业务员完成订单", "完成",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.WAIT_PAY), OrderStatusEnum.COMPLETE, Boolean.TRUE),

    NO_CONFIRM_COMPLETE("NO_CONFIRM_COMPLETE", "业务员完成订单", "完成",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.WAIT_PAY), OrderStatusEnum.COMPLETE, Boolean.TRUE),

    SUBMIT_REMARK("SUBMIT_REMARK", "业务员填写订单备注", "订单备注",ClerkActionTypeEnum.ACTION.value(), Lists.asList(OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_VISIT, OrderStatusEnum.WAIT_QUALITY, OrderStatusEnum.COMPLETE, OrderStatusEnum.CLERK_CANCEL), null, Boolean.FALSE),

    CANCEL("CANCEL", "业务员取消", "取消订单",ClerkActionTypeEnum.BTN.value(), Lists.asList(OrderStatusEnum.WAIT_CONFIRM,OrderStatusEnum.WAIT_VISIT, OrderStatusEnum.WAIT_QUALITY, OrderStatusEnum.WAIT_PAY), OrderStatusEnum.CLERK_CANCEL, Boolean.FALSE),

    SUBMIT_COLLECTION("SUBMIT_COLLECTION", "业务员提交用户收款账户", "收款账户",ClerkActionTypeEnum.ACTION.value(), Lists.asList(), null, Boolean.FALSE),

    SUBMIT_USER_CERT("SUBMIT_USER_CERT", "业务员提交用户证件信息", "添加证件",ClerkActionTypeEnum.ACTION.value(), Lists.asList(), null, Boolean.FALSE),

    // 自卖申请(订单状态已收成 && 无自卖申请记录)
    REQUEST_SELF_SALE("REQUEST_SELF_SALE", "业务员申请自卖", "申请自卖",ClerkActionTypeEnum.BTN.value(), Lists.asList(OrderStatusEnum.COMPLETE), null, Boolean.TRUE),

    // 撤销自卖申请(订单状态已收成 && 自卖申请审核中)
    BACKOUT_SELF_SALE("BACKOUT_SELF_SALE", "业务员撤销自卖申请", "撤销自卖申请",ClerkActionTypeEnum.BTN.value(), Lists.asList(OrderStatusEnum.COMPLETE), null, Boolean.TRUE),

    // 订单状态已收成 && 物流待发货
    DELIVERY("DELIVERY", "业务员发货到公司", "订单发货",ClerkActionTypeEnum.ACTION.value(), Lists.asList(OrderStatusEnum.COMPLETE), null, Boolean.FALSE),

    RESERVE("RESERVE", "业务员预约寄回快递", "预约快递",ClerkActionTypeEnum.ACTION.value(), Lists.asList(OrderStatusEnum.COMPLETE), null, Boolean.FALSE),
    RESET_ORDER_STATUS("RESET_ORDER_STATUS", "重置订单状态", "重置订单",ClerkActionTypeEnum.FIX.value(), Lists.asList(OrderStatusEnum.CLERK_CANCEL, OrderStatusEnum.CANCELLED,OrderStatusEnum.CLOSED), null, Boolean.TRUE),
    ;

    private String actionCode;

    /**
     * 操作名称
     */
    private String actionName;

    /**
     * 操作展示名称
     */
    private String actionText;

    /**
     * 操作类型
     */
    private String actionType;

    /**
     * 执行操作的前置订单状态
     */
    private List<OrderStatusEnum> fromOrderStatus;

    /**
     * 执行操作后的流转订单状态(为空则无状态变更)
     */
    private OrderStatusEnum toOrderStatus;

    /**
     * 额外的条件(初当前订单状态 && 额外条件)
     */
    private Boolean moreCondition;

    ClerkOrderActionEnum(String actionCode, String actionName) {
        this.actionCode = actionCode;
        this.actionName = actionName;
    }

    ClerkOrderActionEnum(String actionCode, String actionName, String actionText, String actionType, List<OrderStatusEnum> fromOrderStatus, OrderStatusEnum toOrderStatus, Boolean moreCondition) {
        this.actionCode = actionCode;
        this.actionName = actionName;
        this.actionText = actionText;
        this.actionType = actionType;
        this.fromOrderStatus = fromOrderStatus;
        this.toOrderStatus = toOrderStatus;
        this.moreCondition = moreCondition;
    }

    public static String getDesc(String actionCode) {
        for (ClerkOrderActionEnum thisEnum : ClerkOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.actionName;
            }
        }
        throw Ex.systemError("未定义的业务员订单操作[{}]", actionCode);
    }

    public static String get(String actionCode) {
        for (ClerkOrderActionEnum thisEnum : ClerkOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.actionName;
            }
        }
        throw Ex.systemError("未定义的业务员订单操作[{}]", actionCode);
    }

    @Override
    public String value() {
        return this.actionCode;
    }

    @Override
    public String named() {
        return this.actionName;
    }

    public String getActionCode() {
        return actionCode;
    }

    public String getActionName() {
        return actionName;
    }

    public String getActionText() {
        return actionText;
    }

    public String getActionType() {
        return actionType;
    }

    public List<OrderStatusEnum> fromOrderStatus() {
        return fromOrderStatus;
    }

    public OrderStatusEnum toOrderStatus() {
        return toOrderStatus;
    }

    public Boolean moreCondition() {
        return moreCondition;
    }
}
